<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
  >
    <buss-material-application-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" />
    <template #footer>
      <a-button key="submit" type="primary" :loading="loading" v-if="showOkButton" @click="handleOk">确 定</a-button>
      <a-button key="delete" type="danger" v-if="showDeleteButton" @click="handleDeleteMainid">删 除</a-button>
      <a-button key="back" @click="handleCancel">关 闭</a-button>
    </template>
  </j-modal>
</template>

<script>
import BussMaterialApplicationForm from './BussMaterialApplicationForm'
import { deleteAction, downFile, getAction, getFileAccessHttpUrl } from '@/api/manage'

export default {
  name: 'BussMaterialApplicationModal',
  components: {
    BussMaterialApplicationForm,
  },
  props: {},
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      curModel: {},
      showDeleteButton: false,
      showOkButton: true,
      loading: false,
    }
  },
  methods: {
    add() {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.add()
      })
    },
    edit(record) {
      this.visible = true
      this.$nextTick(() => {
        //编辑的时候先传入Model
        this.curModel = record
        this.$refs.realForm.edit(record)
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      this.$refs.realForm.submitForm()
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    handleDeleteMainid: function () {
      let deleteUrl = '/procurement/delete'
      console.log(this.curModel)
      if (this.curModel && this.curModel.id) {
        var that = this
        this.$confirm({
          title: '提示',
          content: '是否确认删除该订单?',
          onOk: function () {
            deleteAction(deleteUrl, { id: that.curModel.id })
              .then((res) => {
                if (res.success) {
                  that.$message.success('删除成功')
                  that.$emit('ok')
                  that.close()
                } else {
                  that.$message.warning(res.message)
                }
              })
              .finally(() => {})
          },
        })
      } else {
        this.$message.warning('没有找到此请购单id不能删除')
        return
      }
    },
  },
}
</script>

<style scoped></style>
